Skip to content

docs: document best practice for handling argument errors in MCP tools#891

Merged
Kehrlann merged 6 commits intomodelcontextprotocol:mainfrom
radeshgovind-2005:docs/error-handling-best-practices
Apr 2, 2026
Merged

docs: document best practice for handling argument errors in MCP tools#891
Kehrlann merged 6 commits intomodelcontextprotocol:mainfrom
radeshgovind-2005:docs/error-handling-best-practices

Conversation

@radeshgovind-2005
Copy link
Copy Markdown
Contributor

Resolves #356

Clarify the two-tier error model:

  • Recoverable tool errors: use CallToolResult with isError(true)
  • Protocol-level errors: throw McpError / let exceptions propagate as JSON-RPC errors

Motivation and Context

Issue #356 raised uncertainty about whether tool argument errors should throw
exceptions or be returned as CallToolResult. The maintainer clarified the correct
approach in the thread but it was not yet documented. This PR formalizes that guidance.

How Has This Been Tested?

Documentation-only change. The full test suite passes locally (747 tests, 0 failures).

Breaking Changes

None.

Types of changes

  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added or updated documentation as needed

Additional context

The new section was added under the existing ## Error Handling section in
docs/server.md to keep all error-related documentation in one place.

…ations

Resolves modelcontextprotocol#356

Clarify the two-tier error model:
- Recoverable tool errors: use CallToolResult with isError(true)
- Protocol-level errors: throw McpError / let exceptions propagate as JSON-RPC errors
Copy link
Copy Markdown
Contributor

@Kehrlann Kehrlann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A few comments in the PR.

@Kehrlann Kehrlann self-assigned this Apr 1, 2026
@Kehrlann Kehrlann added documentation Improvements or additions to documentation waiting for user Waiting for user feedback or more details labels Apr 1, 2026
radeshgovind-2005 and others added 3 commits April 1, 2026 16:22
Adds "DB timeout" as an explicit example of an infrastructure error to distinguish from input validation.

Co-authored-by: Daniel Garnier-Moiroux <daniel.garnier-moiroux@broadcom.com>
Folds duplicate domain validation rows in the summary table to improve readability.

Co-authored-by: Daniel Garnier-Moiroux <daniel.garnier-moiroux@broadcom.com>
Replaces the contrived missing argument check with a realistic email validation example per maintainer review. This clarifies that CallToolResult(isError=true) should be used for business logic/domain validation, since MCP natively handles missing required arguments via JSON Schema.
@radeshgovind-2005
Copy link
Copy Markdown
Contributor Author

@Kehrlann Thanks for the review! I've updated the example to use email format validation. I also committed your suggestion for the DB timeout clarification and folded the two validation rows in the table into one. Let me know if everything looks good to go!

@Kehrlann Kehrlann removed the waiting for user Waiting for user feedback or more details label Apr 2, 2026
@Kehrlann Kehrlann self-requested a review April 2, 2026 09:05
@Kehrlann Kehrlann merged commit cd2c21c into modelcontextprotocol:main Apr 2, 2026
21 checks passed
@Kehrlann
Copy link
Copy Markdown
Contributor

Kehrlann commented Apr 2, 2026

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document best Practice for Handling Argument Errors in MCP Tool Rendering

2 participants